package com.mz.ozy.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


import androidx.recyclerview.widget.RecyclerView;

import com.mz.ozy.R;
import com.mz.ozy.activity.me.MsgDetailActivity;
import com.mz.ozy.bean.MsgBean;
import com.mz.ozy.utils.Utils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */

public class MsgAdapter extends RecyclerView.Adapter<MsgAdapter.MyViewHolder> {

    private Context mContext;
    List<MsgBean.PageBean.PageItemsBean> mBeanList;

    public MsgAdapter(Context context, List<MsgBean.PageBean.PageItemsBean> mBeanList) {
        mContext = context;
        this.mBeanList = mBeanList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_msg, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final MsgBean.PageBean.PageItemsBean bean = mBeanList.get(position);
        holder.titleTv.setText(bean.getTitle());
        holder.contentTv.setText(bean.getAbout());
        holder.timeTv.setText(Utils.interceptTime(bean.getCreated()));
        holder.mLlItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, MsgDetailActivity.class);
                intent.putExtra("id", bean.getId());
                intent.putExtra("title", bean.getTitle());
                intent.putExtra("time", bean.getCreated());
                intent.putExtra("content", bean.getTitle());
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mBeanList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.timeTv)
        TextView timeTv;
        @BindView(R.id.contentTv)
        TextView contentTv;
        @BindView(R.id.ll_item)
        LinearLayout mLlItem;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }


    }


}
